<%--
  Created by IntelliJ IDEA.
  User: Teacher
  Date: 2025/4/1
  Time: 14:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>关键字搜索</title>
    <style>
        li {
            list-style: none;
            font-size: 14px;
        }

        div {
            border: 1px solid #0059ff;
            border-top: 0px;
            width: 240px;
            border-bottom-left-radius: 5px;
            border-bottom-right-radius: 5px;
            padding: 3px 10px;
            display: none;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("#spell").keyup(function () {
                $("#d").empty();
                if($(this).val() == ""){
                    $("#d").hide();
                    return;
                }
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/query",
                    data: {"spell": $(this).val()},
                    dataType: "json",
                    success: function (datas) {
                        if(datas.length == 0){
                            $("#d").hide();
                            return;
                        }
                        $("#d").show();
                        $(datas).each(function () {
                            $("#d").append("<li>" + this.message + "</li>");
                        })
                    }
                })
            });
        })
    </script>
</head>
<body>
<input id="spell" type="text" style="width: 262px;">
<div id="d">
</div>
</body>
</html>
